
#include "testCryptObject.h"

CPPUNIT_TEST_SUITE_REGISTRATION (testCryptObject);

void testCryptObject :: setUp (void){
}

void testCryptObject :: tearDown (void) {
	if(obj) delete obj;
}

void testCryptObject :: testGetCryptType (void)
{
	obj = new cryptObject();
	CPPUNIT_ASSERT_EQUAL ((string)"rc4", obj->getType());
}

void testCryptObject :: testSetAndGetCryptType (void)
{
	obj = new cryptObject((string)"rc5");
	CPPUNIT_ASSERT_EQUAL ((string)"rc5", obj->getType());
}


void testCryptObject :: testPerformCryption (void)
{
	obj = new cryptObject((string)"rc4");
	CPPUNIT_ASSERT_EQUAL ((string)"rc4", obj->getType());

	obj->setKey("Key for the cryption");
	string cryptContent = obj->performCryption("Hier ist ein Text");
	CPPUNIT_ASSERT_EQUAL (-1, (int) cryptContent.find("Hier"));

	string clearContent = obj->performCryption(cryptContent);
	CPPUNIT_ASSERT_EQUAL ((string)"Hier ist ein Text", clearContent);

}

void testCryptObject :: testPerformCryptionWithFile (void)
{
	obj = new cryptObject((string)"rc4");
	CPPUNIT_ASSERT_EQUAL ((string)"rc4", obj->getType());

	std::string content = staticObject::loadFromFile("res/testCompressObject_clear");
	obj->setKey("Key for the cryption");
	string cryptContent = obj->performCryption(content);
	CPPUNIT_ASSERT_EQUAL (-1, (int) cryptContent.find("1234567890"));

	string clearContent = obj->performCryption(cryptContent);
	CPPUNIT_ASSERT_EQUAL (content, clearContent);

}
